package com.popwindow;

import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;

/**
 * 自定义POPWINDOWS
 * Created by bichuanfeng on 2017/2/15.
 */

public class Popwindows extends PopupWindow {

    public Popwindows(View view, int width, int height){
        super(view,width,height);
    }

    public void setPopWidth(){
        setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    }

    public void show(View rootView, Location location){
        //显示位置
        if (Location.LEFT.ordinal() == location.ordinal()) {
            showAtLocation(rootView, Gravity.LEFT, 0, 500);
        } else if (Location.RIGHT.ordinal() == location.ordinal()) {
            showAtLocation(rootView, Gravity.RIGHT, 0, 500);
        } else if (Location.BOTTOM.ordinal() == location.ordinal()) {
            showAtLocation(rootView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
        }else if (Location.TOP.ordinal() == location.ordinal()) {
            showAtLocation(rootView, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
        }else if (Location.DOWN.ordinal() == location.ordinal()) {
            showAsDropDown(rootView);
        }
    }



    /**
     * 菜单弹出方向
     */
    public enum Location {
        LEFT,
        RIGHT,
        BOTTOM,
        TOP,
        DOWN
    }
}
